<?php

echo $this->headScript()
      ->prependFile($this->baseUrl('js/index/index.js'),'text/javascript');

$this->title = "Projects";
$this->headTitle($this->title);

if (sizeof($this->paginator)) {

	$index = 1;
	foreach($this->paginator as $project) {
		$print_row = ($index % 3 == 0);
		if ($print_row)
		{
?>
			<div class="row">
<?php
		}
?>
		<div class="span3 thumbnail">
         <h4>
            <?php echo $this->escape($project['name']);?>
            <?php if($project['hide'] == 1): ?>
            <i class="icon-eye-close" rel="tooltip" title="Hidden"></i>
            <?php endif;?>
            <a href="<?=$this->url(array('controller' => 'projects',
                'action' => 'delete',
                'id' => $project['id']), null, true) ?>"
                class="close" rel="tooltip" title="Delete">&times;</a>
         </h4>
			<p><?php echo $this->escape($project['description']);?></p>
         <?php
            $all = ($project['_all'] != null ? (int) $project['_all'] : 0);
            $done = ($project['done'] != null ? (int) $project['done'] : 0);
            if ($all > 0) {
               $percent = (100 * $done) / $all;
            } else {
               $percent = 0;
            }
         ?>
         <div class="progress"
               title="<?=$done . "/" . $all ?>">
            <div class="bar <?=$this->projectProgress($percent) ?>"
               aria-valuetransitiongoal="<?php printf("%.0f", $percent) ?>"></div>
         </div>
         <div class="btn-group">
            <a href="<?=$this->url(array('controller' => 'projects',
                'action' => 'update',
                'id' => $project['id'])) ?>"
                class="btn" rel="tooltip" title="Edit"><i class="icon-edit"></i></a>
            <a class="btn" href="<?=$this->url(array('controller' => 'projects',
                'action' => 'show',
                'id' => $project['id']), null, true) ?>">
               View tasks <i class="icon-tasks"></i>
            </a>
         </div>
		</div>
<?php
		if ($print_row)
		{
?>
			</div><br/>
<?php
		}
		$index++;
	}
   ?>
         <div class="row">
            <div class="span9">
               <?php echo $this->paginator; ?>
               <div class="btn-group dropup">
                     <a href="#" class="btn" rel="tooltip" title="Options">
                        <i class="icon-cog"></i>
                     </a>
                     <button class="btn dropdown-toggle" data-toggle="dropdown">
                        <span class="caret"></span>
                     </button>
                     <ul class="dropdown-menu">
                        <li>
                           <a href="<?= $this->url(array('show_hidden' => 1)) ?>">
                              Show Hidden Projects</a>
                        </li>
                        <li>
                           <a href="<?= $this->url(array('show_hidden' => 2)) ?>">
                              Show Only Hidden</a>
                        </li>
                     </ul>
                  </div>
            </div>
         </div>
   <?php
} else {
?>
         <div class="alert alert-block">
            No projects found.
         </div>
<?php
}
?>